package com.atcc.test.common;

import java.util.UUID;

import javax.annotation.PostConstruct;

import com.atcc.test.domain.TokenModel;
import com.atcc.test.domain.UserInfo;

public class TokenHelper {
	
	private volatile static TokenHelper instance = null;
	
	private TokenHelper() {
	}

	/*
	 * 
	 *  /这个我是不明白的
	 */
	@PostConstruct
	public void init()
	{
		instance=this;
	}
	
	public static TokenHelper getInstance() {
		if(instance == null) {
			synchronized(TokenHelper.class) {
				if(instance == null)
					instance = new TokenHelper();
			}
		}
		return instance;
	}
	
	public TokenModel create(UserInfo userInfo,boolean isPhone) {
		TokenModel tm = new TokenModel();
		String Tokenkey = "";
		if(isPhone) {
			Tokenkey = "usertoken_phone_" + userInfo.getphoneNumber();
		}else {
			Tokenkey = "usertoken_" + userInfo.getphoneNumber();
		}
		String token = UUID.randomUUID().toString().replace("-", "");
		tm.setTokenCode(token);
		tm.setPassword(userInfo.getPassword());
		tm.setName(userInfo.getName());
		tm.setPhoneNumber(userInfo.getphoneNumber());
		return tm ;
	}
}
